/*
 * Copyright 2008, 2009 Kobi Krasnoff
 * 
 * This file is part of "Catch Falling Coins".
 *
 * "Catch Falling Coins" is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * "Catch Falling Coins" is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with "Catch Falling Coins".  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;


public class MainList extends List implements CommandListener {
	private static final String[] str = {"Start Game", "About"};
	private MainMIDlet parent;
	private Command chooseCommand = new Command("Choose", Command.EXIT, 2);
    private Command exitCommand = new Command("Exit", Command.ITEM, 1);
	
	public MainList(MainMIDlet parent) {
		super("Main Menu", List.IMPLICIT, str, null);
		addCommand(chooseCommand);
        addCommand(exitCommand);
        setCommandListener(this);
        this.parent = parent;
	}
	
	public void commandAction(Command c, Displayable d) {
		if (c == exitCommand) {
			parent.exitMIDlet();
        }
		else if (c == chooseCommand) {
			if (this.getString(this.getSelectedIndex()) == "Start Game") {
				parent.setCurrent("Start Game");
            }
            else if (this.getString(this.getSelectedIndex()) == "About") {
            	parent.setCurrent("AboutForm");
            }
            else if (this.getString(this.getSelectedIndex()) == "Continue") {
            	parent.setCurrent("Continue");
            }
		}
	}
	
	public void addContinue() {
        if (this.getString(0) != "Continue") {
            this.insert(0, "Continue", null);
            this.setSelectedIndex(0, true);
        }
    }
    
    public void deleteContinue() {
        if (this.getString(0) == "Continue") {
            this.delete(0);
        }
    }
}
